/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#import "Slot.h"
#import "FunctorCl.h"
//NOTE callit functions cast to Functor[0-6] so use the FunctorFactory

@implementation SlotBaseX

- (id)init:(Functor*)fctr
{
	functor = fctr;
	blocked = false;

	return self;
}

- (id)init:(Functor*)fctr blocked:(bool)bl
{
	functor = fctr;
	blocked = bl;

	return self;
}

- (void)destroy
{
	functor = nil;
	blocked = false;
}

//- (void)notify;

- (void)block { blocked = true; }
- (void)unblock { blocked = false; }
- (bool)blocked { return (blocked); }

@end

@implementation SlotBase

- (void)addFunctor:(int)nArgs cFunction:(void*)f;
{
	blocked = false;
	[super addFunctor:nArgs cFunction:f];
	return self;
}

- (void)destroy
{
	[callbacklist clear];
	blocked = false;
}

//- (void)notify;

- (void)block { blocked = true; }
- (void)unblock { blocked = false; }
- (bool)blocked { return (blocked); }

@end

//NOTE callit functions cast to Functor[0-6] so use the FunctorFactory
@implementation Slot0 

- (void*)callit:(NSMutableArray*)a
{
	[callbacklist track:a];
	return nil;//FIXME return array of return values
}
 
@end

@implementation Slot1

- (void*)callit:(NSMutableArray*)a
{
	[callbacklist track:a];
	return nil;//FIXME return array of return values
}
 
@end

@implementation Slot2

- (void*)callit:(NSMutableArray*)a
{
	[callbacklist track:a];
	return nil;//FIXME return array of return values
}
 
@end

@implementation Slot1X
- (void*)callit:(void*)arg0; 
{
	return ([(Functor1*)functor dof:arg0]);
}
@end

@implementation Slot2X
- (void*)callit:(void*)arg0 arg1:(void*)arg1; 
{
	return ([(Functor2*)functor dof:arg0 arg1:arg1]);
}
@end

